﻿using System;
using System.Collections.Generic;
using System.Text;
using DrawingScreen;
using libCommonClass;
using libInterface;

namespace bmttPPTController.TTServer
{
    public class DrawingScreenManager
    {
        private static DrawingScreenManager _instance;

        public static DrawingScreenManager GetInstance()
        {
            if (_instance == null)
            {
                _instance = new DrawingScreenManager();
            }

            return _instance;
        }

        private FormBackground _formBackground;

        private bool bAvailable = false;

        public void Init()
        {
            try
            {
                this._formBackground = new FormBackground();
                this._formBackground.Show();
                this._formBackground.Hide();

                bAvailable = true;
            }
            catch
            {
                bAvailable = false;
            }
        }

        public void ClearAll()
        {
            this._formBackground.ClearContentOnAllDrawingScreen();
        }

        public delegate void NoArgumentDelegate();

        public void setDrawingScreens(int n)
        {
            this._formBackground.SetDrawingScreen(n);
        }

        public void setCurrentIndex(int index)
        {
            this._formBackground.SetCurrentIndex(index);
        }

        public void ShowDrawingScreen()
        {
            try
            {
                if (bAvailable)
                {
                    this._formBackground.Invoke(new NoArgumentDelegate(this._formBackground.ShowAndEnable));
                }
            }
            catch
            { 
            
            }
        }

        public void HideDrawingScreen()
        {
            try
            {
                if (bAvailable)
                {
                    this._formBackground.Invoke(new NoArgumentDelegate(this._formBackground.HideAndDiable));
                }
            }
            catch
            { 
            
            }
        }

        public void RefreshDrawingScreen()
        {
            if (bAvailable)
            {
                this._formBackground.Invoke(new NoArgumentDelegate(this._formBackground.Invalidate));
            }
        }

        public void ProcessMessage(TTMessage message, IClientInfoProvider provider)
        {
            if (_formBackground != null)
            {
                if (message is CDrawingMessage)
                {
                    _formBackground.ProcessMessage((CDrawingMessage)message, provider);

                    this.RefreshDrawingScreen();
                }
            }
        }

        public void SetIndex(int index)
        {
            this._formBackground.SetCurrentIndex(index);
        }

        public void HideTrayIcon()
        {
            try
            {
                _formBackground.HideTrayIcon();
            }
            catch
            { 
            
            }
        }

        public void Save(String path)
        {
            _formBackground.save(path);
        }


        public void Load(String path)
        {
            _formBackground.load(path);
        }

    }
}






